public class Text2 {
    public static void main(String[] args) {
        TicketWindow04 tw = new TicketWindow04();
        new Thread(tw, "TO ").start();
        new Thread(tw, "T1 ").start();
        new Thread(tw, "T2 ").start();
    }
}
class TicketWindow04 implements Runnable {
    private int ticketNumber = 20;
    @Override
    public void run() {
        while (true) {
            saleTicket();
        }
    }
    public synchronized  void   saleTicket() {
        if (ticketNumber > 0) {
            Thread thread = Thread.currentThread();
            String threadName = thread.getName();
            System.out.println(threadName + "正在售出第" + (ticketNumber--) + "张票");
        }
        else {
            System.exit(0);
        }
    }

}